<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./dist/vue.js"></script>
</head>
<body>
    <div id="app">
        <div id="box1" ref="box1">盒子1</div>
        <div ref="box2">盒子2</div>
    </div>
</body>
<script>
    new Vue({
        el:'#app',
        mounted(){
            // 通过id属性获取DOM节点
            console.log(document.getElementById('box1')) // <div id="box1">盒子</div>  
            // 通过 ref 获取DOM节点
            console.log(this.$refs.box1) // <div id="box1">盒子</div>
            
            // 两种方法获取到的 DOM 节点是一样的，所以在vue 中推荐使用ref 获取dom 节点，就不用给div添加id属性了
            
            console.log(this.$refs.box2) // <div>盒子2</div>
            
            this.$refs.box2.onclick = ()=>{
                console.log('盒子2的点击事件')
            }
        }
    })
</script>
</html>